package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.dto.*;
import com.ruoyi.system.entity.ContractPaymentSchedule;
import com.ruoyi.system.entity.DemandChangeAuditLogDO;
import com.ruoyi.system.entity.DemandChangeRequestDO;
import com.ruoyi.system.mapper.ContractPaymentScheduleMapper;
import com.ruoyi.system.mapper.DemandChangeAuditLogMapper;
import com.ruoyi.system.mapper.DemandChangeRequestMapper;
import com.ruoyi.system.service.IDemandChangeRequestService;
import com.ruoyi.system.service.MsgPushService;
import com.ruoyi.system.enums.MsgTypeEnum;
import com.ruoyi.system.service.ProjectService;
import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.vo.DemandChangeAuditLogVO;
import com.ruoyi.system.vo.DemandChangeRequestVO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 需求变更申请服务实现类
 * 
 * @author ruoyi
 * @since 2024-01-01
 */
@Service
@Slf4j
public class DemandChangeRequestServiceImpl extends ServiceImpl<DemandChangeRequestMapper, DemandChangeRequestDO> implements IDemandChangeRequestService {

    @Resource
    private DemandChangeRequestMapper requestMapper;

    @Resource
    private DemandChangeAuditLogMapper auditLogMapper;

    @Resource
    private ISysUserService userService;

    @Resource
    private ProjectService projectService;

    // 使用 fastjson2 进行 JSON 解析/序列化

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean createDraft(DemandChangeRequestCreateDTO createDTO, Long designerId) {
        try {
            // 1. 验证前端传递的项目信息和设计师信息
            if (createDTO.getProjectInfo() == null) {
                throw new ServiceException("项目信息不能为空");
            }
            if (createDTO.getDesignerInfo() == null) {
                throw new ServiceException("设计师信息不能为空");
            }

            // 2. 创建变更申请（草稿状态）
            DemandChangeRequestDO request = new DemandChangeRequestDO();
            request.setProjectId(createDTO.getProjectId());
            // 使用前端传递的项目信息
            request.setProjectCode(createDTO.getProjectInfo().getProjectCode());
            request.setProjectName(createDTO.getProjectInfo().getProjectName());
            request.setCustomerName(createDTO.getProjectInfo().getCustomerName());
            request.setCurrentStage(createDTO.getProjectInfo().getCurrentStage());
            request.setDesignProjectCode(createDTO.getProjectInfo().getDesignProjectCode());
            request.setConstructionProjectCode(createDTO.getProjectInfo().getConstructionProjectCode());
            request.setChangeType(createDTO.getChangeType());
            request.setChangeContent(createDTO.getChangeContent());
            request.setChangeReason(createDTO.getChangeReason());
            request.setImpactScope(convertToJson(createDTO.getImpactScope()));
            request.setAttachments(convertToJson(createDTO.getAttachments()));
            request.setUrgencyLevel(createDTO.getUrgencyLevel());
            request.setUrgencyReason(createDTO.getUrgencyReason());
            // 使用前端传递的设计师信息
            request.setDesignerId(createDTO.getDesignerInfo().getDesignerId());
            request.setDesignerName(createDTO.getDesignerInfo().getDesignerName());
            request.setStatus(0); // 草稿状态
            request.setSubmitCount(0);
            request.setCreateTime(LocalDateTime.now());
            request.setUpdateTime(LocalDateTime.now());
            request.setIsDeleted(0);

            // 3. 生成唯一变更编号
            String changeNo = generateChangeNo(request.getProjectCode());
            request.setChangeNo(changeNo);

            requestMapper.insert(request);

            return true;
        } catch (Exception e) {
            throw new ServiceException("创建草稿失败: " + e.getMessage());
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean submitForAudit(Long requestId, Long designerId) {
        try {
            // 1. 查询申请信息
            DemandChangeRequestDO request = requestMapper.selectById(requestId);
            if (request == null || request.getIsDeleted() == 1) {
                throw new ServiceException("变更申请不存在");
            }
            if (!request.getDesignerId().equals(designerId)) {
                throw new ServiceException("无权限操作此申请");
            }
            if (request.getStatus() != 0) {
                throw new ServiceException("只有草稿状态的申请才能提交审核");
            }
            if (request.getSubmitCount() >= 2) {
                throw new ServiceException("申请已提交2次，无法再次提交");
            }

            // 2. 验证必填字段
            validateRequiredFields(request);

            // 3. 生成变更编号
            if (StringUtils.isEmpty(request.getChangeNo())) {
                String changeNo = generateChangeNo(request.getProjectCode());
                request.setChangeNo(changeNo);
            }

            // 4. 更新申请状态
            request.setStatus(1); // 待审核
            request.setSubmitCount(request.getSubmitCount() + 1);
            request.setUpdateTime(LocalDateTime.now());
            requestMapper.updateById(request);

            // 5. 记录审核日志
            recordAuditLog(requestId, "submit", null, null, designerId, "提交审核");

            // TODO: 发送消息通知管理员

            return true;
        } catch (Exception e) {
            throw new ServiceException("提交审核失败: " + e.getMessage());
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateDraft(Long requestId, DemandChangeRequestCreateDTO createDTO, Long designerId) {
        try {
            // 1. 查询申请信息
            DemandChangeRequestDO request = requestMapper.selectById(requestId);
            if (request == null || request.getIsDeleted() == 1) {
                throw new ServiceException("变更申请不存在");
            }
            if (!request.getDesignerId().equals(designerId) && !SecurityUtils.hasRole("admin")) {
                throw new ServiceException("无权限操作此申请");
            }
            if (request.getStatus() != 0) {
                throw new ServiceException("只有草稿状态的申请才能编辑");
            }

            // 2. 验证前端传递的项目信息和设计师信息
            if (createDTO.getProjectInfo() == null) {
                throw new ServiceException("项目信息不能为空");
            }
            if (createDTO.getDesignerInfo() == null) {
                throw new ServiceException("设计师信息不能为空");
            }

            // 3. 更新申请信息
            request.setChangeType(createDTO.getChangeType());
            request.setChangeContent(createDTO.getChangeContent());
            request.setChangeReason(createDTO.getChangeReason());
            request.setImpactScope(convertToJson(createDTO.getImpactScope()));
            request.setAttachments(convertToJson(createDTO.getAttachments()));
            request.setUrgencyLevel(createDTO.getUrgencyLevel());
            request.setUrgencyReason(createDTO.getUrgencyReason());
            // 更新项目信息（使用前端传递的数据）
            request.setProjectCode(createDTO.getProjectInfo().getProjectCode());
            request.setProjectName(createDTO.getProjectInfo().getProjectName());
            request.setCustomerName(createDTO.getProjectInfo().getCustomerName());
            request.setCurrentStage(createDTO.getProjectInfo().getCurrentStage());
            request.setDesignProjectCode(createDTO.getProjectInfo().getDesignProjectCode());
            request.setConstructionProjectCode(createDTO.getProjectInfo().getConstructionProjectCode());
            request.setProjectId(createDTO.getProjectId());
            // 更新设计师信息（使用前端传递的数据）
            request.setDesignerId(createDTO.getDesignerInfo().getDesignerId());
            request.setDesignerName(createDTO.getDesignerInfo().getDesignerName());
            request.setUpdateTime(LocalDateTime.now());

            requestMapper.updateById(request);

            return true;
        } catch (Exception e) {
            throw new ServiceException("更新草稿失败: " + e.getMessage());
        }
    }

    @Override
    public List<DemandChangeRequestVO> getChangeRequestList(DemandChangeRequestQueryDTO queryDTO) {
        // 1. 构建查询条件
        LambdaQueryWrapper<DemandChangeRequestDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(DemandChangeRequestDO::getIsDeleted, 0);

        if (queryDTO.getProjectId() != null) {
            queryWrapper.eq(DemandChangeRequestDO::getProjectId, queryDTO.getProjectId());
        }
        if (StringUtils.isNotEmpty(queryDTO.getProjectName())) {
            queryWrapper.like(DemandChangeRequestDO::getProjectName, queryDTO.getProjectName());
        }
        if (StringUtils.isNotEmpty(queryDTO.getChangeType())) {
            queryWrapper.eq(DemandChangeRequestDO::getChangeType, queryDTO.getChangeType());
        }
        if (queryDTO.getStatus() != null) {
            queryWrapper.eq(DemandChangeRequestDO::getStatus, queryDTO.getStatus());
        }
        if (queryDTO.getDesignerId() != null) {
            queryWrapper.eq(DemandChangeRequestDO::getDesignerId, queryDTO.getDesignerId());
        }
        if (StringUtils.isNotEmpty(queryDTO.getDesignerName())) {
            queryWrapper.like(DemandChangeRequestDO::getDesignerName, queryDTO.getDesignerName());
        }
        if (StringUtils.isNotEmpty(queryDTO.getChangeNo())) {
            queryWrapper.like(DemandChangeRequestDO::getChangeNo, queryDTO.getChangeNo());
        }
        if (StringUtils.isNotEmpty(queryDTO.getUrgencyLevel())) {
            queryWrapper.eq(DemandChangeRequestDO::getUrgencyLevel, queryDTO.getUrgencyLevel());
        }
        if (queryDTO.getCreateTimeStart() != null) {
            queryWrapper.ge(DemandChangeRequestDO::getCreateTime, queryDTO.getCreateTimeStart());
        }
        if (queryDTO.getCreateTimeEnd() != null) {
            queryWrapper.le(DemandChangeRequestDO::getCreateTime, queryDTO.getCreateTimeEnd());
        }

        // 2. 排序
        if (StringUtils.isNotEmpty(queryDTO.getOrderBy())) {
            if ("desc".equalsIgnoreCase(queryDTO.getOrderDirection())) {
                queryWrapper.orderByDesc(getOrderByField(queryDTO.getOrderBy()));
            } else {
                queryWrapper.orderByAsc(getOrderByField(queryDTO.getOrderBy()));
            }
        } else {
            queryWrapper.orderByDesc(DemandChangeRequestDO::getCreateTime);
        }

        queryWrapper.orderByAsc(DemandChangeRequestDO::getStatus);

        // 3. 查询数据
        List<DemandChangeRequestDO> requests = requestMapper.selectList(queryWrapper);

        // 4. 转换为VO
        return requests.stream().map(this::convertToVO).collect(Collectors.toList());
    }

    @Override
    public DemandChangeRequestVO getChangeRequestDetail(Long requestId) {
        // 1. 查询申请信息
        DemandChangeRequestDO request = requestMapper.selectById(requestId);
        if (request == null || request.getIsDeleted() == 1) {
            throw new ServiceException("变更申请不存在");
        }

        ProjectDTO projectById = projectService.getProjectById(request.getProjectId());

        // 2. 转换为VO
        DemandChangeRequestVO vo = convertToVO(request);

        if (projectById != null) {
            vo.setCustomerId(projectById.getH5UserId());
        }
        // 3. 查询审核记录
        List<DemandChangeAuditLogDO> logs = auditLogMapper.selectList(
                new LambdaQueryWrapper<DemandChangeAuditLogDO>()
                        .eq(DemandChangeAuditLogDO::getRequestId, requestId)
                        .orderByDesc(DemandChangeAuditLogDO::getAuditTime)
        );
        vo.setAuditLogs(logs.stream().map(this::convertLogToVO).collect(Collectors.toList()));

        return vo;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean auditChangeRequest(DemandChangeRequestAuditDTO auditDTO, Long auditorId) {
        try {
            // 1. 查询申请信息
            DemandChangeRequestDO request = requestMapper.selectById(auditDTO.getRequestId());
            if (request == null || request.getIsDeleted() == 1) {
                throw new ServiceException("变更申请不存在");
            }
            if (request.getStatus() != 1) {
                throw new ServiceException("申请状态不允许审核");
            }

            // 2. 更新申请状态
            int newStatus = "pass".equals(auditDTO.getAuditResult()) ? 2 : 3; // 审核通过或驳回
            request.setStatus(newStatus);
            request.setAuditBy(auditorId);
            request.setAuditName(getUserName(auditorId));
            request.setAuditTime(LocalDateTime.now());
            request.setAuditOpinion(auditDTO.getAuditOpinion());
            request.setAuditImpactScope(convertToJson(auditDTO.getAuditImpactScope()));
            request.setUpdateTime(LocalDateTime.now());

            requestMapper.updateById(request);

            // 3. 记录审核日志
            recordAuditLog(request.getId(), "pass".equals(auditDTO.getAuditResult()) ? "pass" : "reject", 
                          auditDTO.getAuditResult(), auditDTO.getAuditOpinion(), auditorId, auditDTO);

            // 4. 发送消息通知
//            sendChangeNotification(request, auditDTO, auditorId);

            return true;
        } catch (Exception e) {
            throw new ServiceException("审核变更申请失败: " + e.getMessage());
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean approveChangeRequest(DemandChangeRequestAuditDTO auditDTO, Long auditorId) {
        try {
            // 1. 查询申请信息
            DemandChangeRequestDO request = requestMapper.selectById(auditDTO.getRequestId());
            if (request == null || request.getIsDeleted() == 1) {
                throw new ServiceException("变更申请不存在");
            }
            if (request.getStatus() != 1) {
                throw new ServiceException("只有待审核状态的申请才能通过审核");
            }

            // 2. 更新申请状态为审核通过
            request.setStatus(2); // 审核通过
            request.setAuditBy(auditorId);
            request.setAuditName(getUserName(auditorId));
            request.setAuditTime(LocalDateTime.now());
            request.setAuditOpinion(auditDTO.getAuditOpinion());
            request.setAuditImpactScope(convertToJson(auditDTO.getAuditImpactScope()));
            request.setUpdateTime(LocalDateTime.now());

            requestMapper.updateById(request);

            // 3. 记录审核日志
            recordAuditLog(request.getId(), "pass", "pass", auditDTO.getAuditOpinion(), auditorId, auditDTO);

            // 4. 发送消息通知设计师
//            sendChangeNotification(request, auditDTO, auditorId);

            return true;
        } catch (Exception e) {
            throw new ServiceException("通过审核失败: " + e.getMessage());
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean rejectChangeRequest(DemandChangeRequestAuditDTO auditDTO, Long auditorId) {
        try {
            // 1. 查询申请信息
            DemandChangeRequestDO request = requestMapper.selectById(auditDTO.getRequestId());
            if (request == null || request.getIsDeleted() == 1) {
                throw new ServiceException("变更申请不存在");
            }
            if (request.getStatus() != 1) {
                throw new ServiceException("只有待审核状态的申请才能驳回");
            }

            // 2. 更新申请状态为审核驳回
            request.setStatus(3); // 审核驳回
            request.setAuditBy(auditorId);
            request.setAuditName(getUserName(auditorId));
            request.setAuditTime(LocalDateTime.now());
            request.setAuditOpinion(auditDTO.getAuditOpinion());
            request.setAuditImpactScope(convertToJson(auditDTO.getAuditImpactScope()));
            request.setUpdateTime(LocalDateTime.now());

            requestMapper.updateById(request);

            // 3. 记录审核日志
            recordAuditLog(request.getId(), "reject", "reject", auditDTO.getAuditOpinion(), auditorId, auditDTO);

            return true;
        } catch (Exception e) {
            throw new ServiceException("驳回审核失败: " + e.getMessage());
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean cancelChangeRequest(Long requestId, Long operatorId) {
        try {
            // 1. 查询申请信息
            DemandChangeRequestDO request = requestMapper.selectById(requestId);
            if (request == null || request.getIsDeleted() == 1) {
                throw new ServiceException("变更申请不存在");
            }
            if (request.getStatus() == 4) {
                throw new ServiceException("已执行的申请不能取消");
            }

            // 2. 更新申请状态
            request.setStatus(5); // 已取消
            request.setUpdateTime(LocalDateTime.now());
            requestMapper.updateById(request);

            // 3. 记录审核日志
            recordAuditLog(requestId, "cancel", null, "取消申请", operatorId, null);

            return true;
        } catch (Exception e) {
            throw new ServiceException("取消变更申请失败: " + e.getMessage());
        }
    }

    /**
     * 验证必填字段
     */
    private void validateRequiredFields(DemandChangeRequestDO request) {
        if (StringUtils.isEmpty(request.getChangeType())) {
            throw new ServiceException("请完善变更类型");
        }
        if (StringUtils.isEmpty(request.getChangeReason())) {
            throw new ServiceException("请完善变更原因");
        }
        if (StringUtils.isEmpty(request.getChangeContent())) {
            throw new ServiceException("请完善变更内容描述");
        }
    }

    /**
     * 生成变更编号
     * 规则：BG + 项目编号 + 6位流水号
     * 示例：BGAB202510001000001
     */
    private String generateChangeNo(String projectCode) {
        // 1. 查询当前项目编号的最大流水号
        Integer maxSeq = requestMapper.getMaxChangeNoSeq(projectCode);
        
        // 2. 生成下一个流水号（6位数字，不足补零）
        int nextSeq = (maxSeq == null ? 0 : maxSeq) + 1;
        String sequence = String.format("%06d", nextSeq);
        
        // 3. 拼接变更编号：BG + 项目编号 + 6位流水号
        return "BG" + projectCode + sequence;
    }


    /**
     * 获取用户姓名
     */
    private String getUserName(Long userId) {
        try {
            SysUser user = userService.selectUserById(userId);
            return user != null ? user.getNickName() : "用户-" + userId;
        } catch (Exception e) {
            log.warn("获取用户姓名失败，用户ID: {}, 错误: {}", userId, e.getMessage());
            return "用户-" + userId;
        }
    }

    /**
     * 转换为JSON字符串
     */
    private String convertToJson(Object obj) {
        if (obj == null) {
            return null;
        }
        try {
            return JSON.toJSONString(obj);
        } catch (Exception e) {
            return null;
        }
    }

    /**
     * 记录审核日志
     */
    private void recordAuditLog(Long requestId, String auditType, String auditResult, String auditOpinion, 
                              Long auditorId, Object auditData) {
        DemandChangeAuditLogDO log = new DemandChangeAuditLogDO();
        log.setRequestId(requestId);
        log.setAuditType(auditType);
        log.setAuditResult(auditResult);
        log.setAuditOpinion(auditOpinion);
        log.setAuditorId(auditorId);
        log.setAuditorName(getUserName(auditorId));
        log.setAuditTime(LocalDateTime.now());
        log.setCreateTime(LocalDateTime.now());

        // 如果是审核操作，记录审核数据
        if (auditData instanceof DemandChangeRequestAuditDTO) {
            DemandChangeRequestAuditDTO auditDTO = (DemandChangeRequestAuditDTO) auditData;
            log.setAuditImpactScope(convertToJson(auditDTO.getAuditImpactScope()));
            log.setSyncModules(convertToJson(auditDTO.getSyncModules()));
        }

        auditLogMapper.insert(log);
    }

    /**
     * 转换为VO
     */
    private DemandChangeRequestVO convertToVO(DemandChangeRequestDO request) {
        DemandChangeRequestVO vo = new DemandChangeRequestVO();
        BeanUtils.copyProperties(request, vo);
        
        // 设置类型名称
        vo.setChangeTypeName(getChangeTypeName(request.getChangeType()));
        vo.setStatusName(getStatusName(request.getStatus()));
        vo.setUrgencyLevelName(getUrgencyLevelName(request.getUrgencyLevel()));
        
        // 解析JSON字段
        if (StringUtils.isNotEmpty(request.getImpactScope())) {
            try {
                DemandChangeRequestVO.ImpactScopeVO impactScope =
                        JSON.parseObject(request.getImpactScope(), DemandChangeRequestVO.ImpactScopeVO.class);
                vo.setImpactScope(impactScope);
            } catch (Exception e) {
                vo.setImpactScope(null);
            }
        }
        
        if (StringUtils.isNotEmpty(request.getAttachments())) {
            try {
                List<String> attachments = JSON.parseArray(request.getAttachments(), String.class);
                vo.setAttachments(attachments);
            } catch (Exception e) {
                vo.setAttachments(new ArrayList<>());
            }
        }
        
        if (StringUtils.isNotEmpty(request.getAuditImpactScope())) {
            try {
                DemandChangeRequestVO.ImpactScopeVO auditImpactScope =
                        JSON.parseObject(request.getAuditImpactScope(), DemandChangeRequestVO.ImpactScopeVO.class);
                vo.setAuditImpactScope(auditImpactScope);
            } catch (Exception e) {
                vo.setAuditImpactScope(null);
            }
        }
        
        return vo;
    }

    /**
     * 转换日志为VO
     */
    private DemandChangeAuditLogVO convertLogToVO(DemandChangeAuditLogDO log) {
        DemandChangeAuditLogVO vo = new DemandChangeAuditLogVO();
        BeanUtils.copyProperties(log, vo);
        
        vo.setAuditTypeName(log.getAuditType());
        vo.setAuditResultName(log.getAuditResult());
        
        // 解析JSON字段
        if (StringUtils.isNotEmpty(log.getAuditImpactScope())) {
            try {
                DemandChangeRequestVO.ImpactScopeVO impactScope =
                        JSON.parseObject(log.getAuditImpactScope(), DemandChangeRequestVO.ImpactScopeVO.class);
                vo.setAuditImpactScope(impactScope);
            } catch (Exception e) {
                vo.setAuditImpactScope(null);
            }
        }
        
        if (StringUtils.isNotEmpty(log.getSyncModules())) {
            try {
                List<String> syncModules = JSON.parseArray(log.getSyncModules(), String.class);
                vo.setSyncModules(syncModules);
            } catch (Exception e) {
                vo.setSyncModules(new ArrayList<>());
            }
        }
        
        return vo;
    }

    /**
     * 获取排序字段
     */
    private com.baomidou.mybatisplus.core.toolkit.support.SFunction<DemandChangeRequestDO, ?> getOrderByField(String orderBy) {
        switch (orderBy) {
            case "create_time":
                return DemandChangeRequestDO::getCreateTime;
            case "update_time":
                return DemandChangeRequestDO::getUpdateTime;
            case "status":
                return DemandChangeRequestDO::getStatus;
            case "change_type":
                return DemandChangeRequestDO::getChangeType;
            default:
                return DemandChangeRequestDO::getCreateTime;
        }
    }

    /**
     * 获取变更类型名称
     */
    private String getChangeTypeName(String changeType) {
        switch (changeType) {
            case "1":
                return "设计方案变更";
            case "2":
                return "材料物料变更";
            case "3":
                return "合同变更";
            case "4":
                return "施工项变更";
            case "5":
                return "工期变更";
            case "6":
                return "其他变更";
            default:
                return changeType;
        }
    }

    /**
     * 获取状态名称
     */
    private String getStatusName(Integer status) {
        switch (status) {
            case 0:
                return "草稿";
            case 1:
                return "待审核";
            case 2:
                return "审核通过";
            case 3:
                return "审核驳回";
            case 4:
                return "已执行";
            case 5:
                return "已取消";
            default:
                return "未知";
        }
    }

    /**
     * 获取紧急程度名称
     */
    private String getUrgencyLevelName(String urgencyLevel) {
        switch (urgencyLevel) {
            case "normal":
                return "普通";
            case "urgent":
                return "紧急";
            case "critical":
                return "特急";
            default:
                return urgencyLevel;
        }
    }

    /**
     * 获取审核类型名称
     */
    private String getAuditTypeName(String auditType) {
        switch (auditType) {
            case "submit":
                return "提交审核";
            case "pass":
                return "审核通过";
            case "reject":
                return "审核驳回";
            case "resubmit":
                return "重新提交";
            case "cancel":
                return "取消申请";
            default:
                return auditType;
        }
    }

    /**
     * 获取审核结果名称
     */
    private String getAuditResultName(String auditResult) {
        switch (auditResult) {
            case "pass":
                return "通过";
            case "reject":
                return "驳回";
            default:
                return auditResult;
        }
    }


    /**
     * H5用户信息内部类
     */
    private static class H5UserInfo {
        private Long userId;
        private String userName;

        // Getters and Setters
        public Long getUserId() { return userId; }
        public void setUserId(Long userId) { this.userId = userId; }
        public String getUserName() { return userName; }
        public void setUserName(String userName) { this.userName = userName; }
    }
}
